﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Room = UserControl_Room;
using Col = Column<string, System.Type, int>;
using System.Data;
using System.Collections;
using Guru.Web.UI;

public partial class UserControl_FloorDiagram : GuruUserControl
{
    #region Properties    
    public string FloorID
    {
        set;
        get;
    }
    public string FloorName
    {
        set 
        {
            uxFloorName.Text = value;
        }
        get
        {
            return uxFloorName.Text;
        }
    }
    public DataTable Rooms
    {
        get;
        set;
    }   
    public HSMEnums.SelectionMode RoomSelectionMode
    {
        set
        {
            ViewState["RoomSelectionMode"] = value;
        }
        get 
        {
            if (ViewState["RoomSelectionMode"] == null)
                return HSMEnums.SelectionMode.None;
            else 
                return (HSMEnums.SelectionMode)Enum.Parse(typeof(HSMEnums.SelectionMode), ViewState["RoomSelectionMode"].ToString());
        }
    }
    public HSMEnums.SelectionMode FloorSelectionMode
    {
        set
        {
            ViewState["FloorSelectionMode"] = value;
        }
        get
        {
            if (ViewState["FloorSelectionMode"] == null)
                return HSMEnums.SelectionMode.None;
            else
                return (HSMEnums.SelectionMode)Enum.Parse(typeof(HSMEnums.SelectionMode), ViewState["FloorSelectionMode"].ToString());
        }
    }
    public List<string> SelectedRooms
    {
        get 
        {
            List<string> selectedRooms = new List<string>();
            foreach (RepeaterItem item in uxRoomList.Items)
            {
                Room room = item.FindControl("uxRoom") as Room;
                if (room != null && room.Selected)
                    selectedRooms.Add(room.RoomID);
            }
            return selectedRooms;
        }
    }
    #endregion

    #region Data Binding
    protected void uxRoomList_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        switch (e.Item.ItemType)
        {
            case ListItemType.Item:
            case ListItemType.AlternatingItem:
                DataRowView dataView = (DataRowView)e.Item.DataItem;
                Room room = (Room)e.Item.FindControl("uxRoom");
                room.RoomName = dataView["RoomName"].ToString();
                room.RoomID = dataView["RoomID"].ToString();
                room.CurrentInvoiceID = dataView["CurrentInvoice"].ToSafeString();
                if (dataView["Status"].IsNotNull())
                    room.Status = (HSMEnums.RoomStatus)Enum.Parse(typeof(HSMEnums.RoomStatus), dataView["Status"].ToString());                   
                else room.Status = HSMEnums.RoomStatus.Empty;
                room.SelectionMode = this.RoomSelectionMode;
                if (dataView["IsSelected"].IsNotNull())
                {
                    room.Selected = dataView["IsSelected"].ToString().Equals("1");
                }
                break;
        } 
    }
    public void DataBind()
    {
        this.uxRoomList.DataSource = this.Rooms;
        this.uxRoomList.DataBind();
    }
    #endregion
}
